﻿using LL2024.Models.CommonLibraries;
using LL2024.Models.CommonLibraries.Model;
using LL2024.Models.CommonLibraries.Services;
using System.Windows;

namespace WpfApp2
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public class sdsada
        {
            public string ddd { get; set; }
            public string ddd2 { get; set; }

        }
        public MainWindow()
        {
            // Arrange
            string left = "15.75";
            decimal right = 4.25m;
            var dara = GetLocalIPAddress();
            // Act
            // Arrange


            // Assert

            var nddd = "cw1".ToEncrypt();
            var ddsas = nddd.ToDecrypt("2");
            var result = SafeMath.Add<decimal>(left, right, precision: 2);
            var dde = Common.ValidatePassword("sdsdaasd111111111A@");
            InitializeComponent();
            var dsadsdad = new sdsada { ddd = "1", ddd2 = "2" };
            var dd = new MessageModel<sdsada>
            {
                Status = 0,
                Msg = "Success",
                Data = dsadsdad
            };

            var ddd = dd.ToString();
            var ds = ddd.ToMessageModel<sdsada>();

            Loaded += MainWindow_Loaded;

            ///22
            ///


        }

        private async void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            var rs = await Uapis.GetNetInfomationAsync();
            var rs1 = await Uapis.GetWeatherInfoAsync("北京市");
            var rs2 = await Uapis.IsLocationKunmingAsync();
            var rs3 = await Uapis.GetProhibitedInfoAsync("你个大沙比");

            var dt = await Common.GetNetDateTime();
            var executor = new TaskChunkExecutor();
            var list = new List<string> { "item1", "item2", "item3", "item4", "item5" };

            // 定义具体的任务执行逻辑
            TaskChunkExecutor.TaskDelegate<string> taskDelegate = async (chunk) =>
            {
                return await Task.Run(() =>
                {
                    var result = new List<Dictionary<string, string>>();
                    foreach (var item in chunk)
                    {
                        var dict = new Dictionary<string, string>
                    {
                        { "Item", item }
                    };
                        result.Add(dict);
                    }
                    return result;
                });
            };

            // 调用类库的方法，传入任务执行逻辑
            var result = await executor.ExecuteAsync(list, 2, taskDelegate);

            // 输出结果
            foreach (var chunkResult in result)
            {
                foreach (var dict in chunkResult)
                {
                    foreach (var kvp in dict)
                    {
                        Console.WriteLine($"{kvp.Key}: {kvp.Value}");
                    }
                }

            }
        }

        public static string GetLocalIPAddress()
        {
            using (System.Net.Sockets.Socket socket = new System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Dgram, 0))
            {
                socket.Connect("8.8.8.8", 65530);
                System.Net.IPEndPoint? endPoint = socket.LocalEndPoint as System.Net.IPEndPoint;
                return endPoint?.Address?.ToString() ?? "0.0.0.0";
            }
        }
    }
}